package com.example.aircraftwar.codes.goal;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.example.aircraftwar.R;

import java.util.List;

public class RecordAdapter extends ArrayAdapter<Record> {
    private int resourceId;
    public RecordAdapter(Context context, int textViewResourceId, List<Record> objects){
        super(context,textViewResourceId,objects);
        resourceId = textViewResourceId;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Record record = getItem(position); //获取当前项的Goal实例
        View view;
        if(convertView == null){
            view = LayoutInflater.from(getContext()).inflate(resourceId,parent,false);
        } else {
            view = convertView;
        }
        TextView rank = (TextView) view.findViewById(R.id.rank);
        TextView name = (TextView) view.findViewById(R.id.name);
        TextView score = (TextView) view.findViewById(R.id.score);
        TextView time = (TextView) view.findViewById(R.id.time);
        rank.setText(String.valueOf(record.getRank()));
        name.setText(record.getName());
        score.setText(String.valueOf(record.getScore()));
        time.setText(record.getTime());
        return view;
    }
}
